import {Component, OnInit} from '@angular/core';
import {NavigationEnd, NavigationStart, Router} from '@angular/router';
import {CommonService} from './service/common-service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers: [CommonService]  // 供应者
})
export class AppComponent implements OnInit {
  title = 'lxangular';

  constructor(
    private router: Router,
    public commonService: CommonService) {
  }

  ngOnInit(): void {
  this.commonService.getLocalStorageFromJson();
    this.router.events.subscribe((evt) => {
      if (!(evt instanceof NavigationEnd)) {
        if (evt instanceof NavigationStart) {
          this.commonService.getLocalStorageFromJson();
        }
        return;
      }
      window.scrollTo(0, 0);
    });
  }

}
